package cn.zjh.base.utils;

import cn.zjh.org.domain.ShopAuditLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

@Component
public class EmailUtil {

    //注入发送邮件的封装类
    @Autowired
    private JavaMailSender javaMailSender;

    /**
     * 发送成功信息
     */
    public void sendPassEmail (ShopAuditLog shopAuditLog)  {
        try {
            // 1.创建复杂邮件对象
            MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
            helper.setFrom("1359156358@qq.com");
            helper.setSubject("宠物乐园店铺入驻结果通知");
            // 3.设置文本内容，第二个参数 true 代表是否是一个html内容
            helper.setText("<h1>亲，您的店铺入驻申请信息我平台已审核通过，请点击下方链接激活店铺</h1>"+
                    "店铺激活链接：<a href='http://localhost:8080/shop/"+shopAuditLog.getShopId()+"'>点我激活店铺</a>",true);
            // 5.设置收件人
            helper.setTo("1359156358@qq.com");
            // 6.发送邮件
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            e.printStackTrace();
        }

    }


    /**
     * 发送驳回信息
     */
    public void sendRejectEmail(ShopAuditLog shopAuditLog){
        try {
            // 1.创建复杂邮件对象
            MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
            helper.setFrom("1359156358@qq.com");
            helper.setSubject("宠物乐园店铺入驻结果通知");
            // 3.设置文本内容，第二个参数 true 代表是否是一个html内容
            //"你的店铺通过审核，请点击激活链接！！！"+"激活后使用:'"+shopAuditLog.getNote()+"',"+"激活链接: http://localhost:8080/shop/audit/"+shopAuditLog.getShopId()
            helper.setText("亲，您的店铺入驻申请信息我平台已审核通过，请点击下方链接激活店铺"+ "店铺激活链接：<a href='http://localhost:8080/shop/"+shopAuditLog.getShopId()+"'>点我激活店铺</a>");
            // 5.设置收件人
            helper.setTo("595847630@qq.com");
            // 6.发送邮件
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            e.printStackTrace();
        }

    }


    /**
     * 发送拒绝信息
     */
    public void sendCancelEmail(ShopAuditLog shopAuditLog){
        try {
            // 1.创建复杂邮件对象
            MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
            helper.setFrom("1359156358@qq.com");
            helper.setSubject("宠物乐园店铺入驻结果通知");
            // 3.设置文本内容，第二个参数 true 代表是否是一个html内容
            helper.setText("您好，您的店铺入驻申请信息未通过已被我平台取消,如有疑问请您联系客服",false);
            // 5.设置收件人
            helper.setTo("595847630@qq.com");
            // 6.发送邮件
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            e.printStackTrace();
        }

    }

}
